package com.gxuwz.business.action;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class BaseAction extends ActionSupport {	

	private static final long serialVersionUID = -5391490758289533136L;

	protected Integer page;//第几页
	protected Integer limit;//每页数据条数
	protected String action;
	
	protected String forwardView;//自定义的跳转页面
	protected HttpServletResponse response;//获取response
	protected HttpServletRequest request;//获取response
	protected PrintWriter printWriter;//获取输出
	
	protected Map<Object, Object> boolMap = new HashMap<Object, Object>();; //用于构造JSONObject
	protected String jsonString;//字符串存储Json对象用于返回
	protected JSONObject JsonData;//存放返回的数据
	protected JSONArray jsonArray;//Json数组
	protected String IS = "isSucceed"; //作为isSucceed的键构造JSON
	protected boolean isSucceed = false; //方法是否执行成功
	protected String key;//模糊查询关键字
	protected String timeSection;//接收时间段
	protected List<Date> dateList;//存放时间段
	protected List<String> dateStringList;//存放字符型的时间段
	
	/**
	 * @deprecated 返回Json对象的字符串形式(目前只用于真假键值对)
	 * @author Timo
	 * 为什么会有这条线~~~
	 */
	public String jsonToString(boolean bool){
		boolMap.put(IS, bool);
		return JSONObject.fromObject(boolMap).toString();
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	private String[] delids;


	public String[] getDelids() {
		return delids;
	}

	public void setDelids(String[] delids) {
		this.delids = delids;
	}
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	protected String getContextPath() {
		return getRequest().getContextPath();
	}
	public HttpServletResponse getResponse(){
		return ServletActionContext.getResponse();
	}
	/**
	 * 
	 * @param paramName
	 * @return
	 */
	protected String getParameters(String paramName) {
		HttpServletRequest req =ServletActionContext.getRequest();
		return req.getParameter(paramName);
	}

	protected HttpSession getSession() {
		return getRequest().getSession();
	}
	
	public String getRootPath(){
		ActionContext ac = ActionContext.getContext();
		ServletContext sc = (ServletContext) ac
				.get(ServletActionContext.SERVLET_CONTEXT);
		String rootURL = sc.getRealPath("/");
		return rootURL;
	}

	public String getForwardView() {
		return forwardView;
	}

	public String getJsonString() {
		return jsonString;
	}

	

	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}

	public JSONObject getJsonData() {
		return JsonData;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setTimeSection(String timeSection) {
		this.timeSection = timeSection;
	}

	public JSONArray getJsonArray() {
		return jsonArray;
	}

	public void setJsonArray(JSONArray jsonArray) {
		this.jsonArray = jsonArray;
	}

	
	

	
}
